package com.wedding.mq;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MQProducer {
	public static void main(String[] args) throws IOException, TimeoutException {
		Connection connection = MQUtil.getConnection();
		//3.通过Connection 创建一个 Channel
		Channel channel = connection.createChannel();
		// 声明（创建）队列
        channel.queueDeclare("q4test", true, false, false, null);
		/**
		 * basicPublish(String exchange, String routingKey, BasicProperties props, byte[] body)
		 * exchange:指定交换机 不指定 则默认 （AMQP default交换机） 通过routingkey进行匹配 
		 * props 消息属性
		 * body 消息体
		 */
		//4.通过Channel发送数据
		for(int i = 0; i < 5; i++){
		  System.out.println("生产消息:" + i);
		  String msg = "Hello RabbitMQ" + i;
	      channel.basicPublish("", "q4test", null, msg.getBytes());
		}
		
		//5.记得关闭相关的连接
		channel.close();
		connection.close();
	}
}
